package br.edu.ufcg.splab.io;

import static org.junit.Assert.assertTrue;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

import br.edu.ufcg.splab.core.InterfaceGenerate;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.exceptions.LTSBTException;
import br.edu.ufcg.splab.generator.TestCaseGenerator;
import br.edu.ufcg.splab.generator.TestSuite;
import br.edu.ufcg.splab.parser.GraphToAnnotatedGraphParser;
import br.edu.ufcg.splab.util.ReadTGF;

public class TestSuiteXMLParserTest {
	
	@Test
	public void smallTestSuite(){

		String graphOneConditionBeginningFilePath = "./test-data/input/OneConditionBegining.tgf";
			String graphOneConditionBeginningOutputFilePath = "./test-data/output/LTSBT_OneConditionBegining.xml";
			ReadTGF TGFReader = new ReadTGF();
			try {
				InterfaceGraph correspondentGraph = TGFReader.getGraph(graphOneConditionBeginningFilePath);
				InterfaceGraph annotatedGraph = new GraphToAnnotatedGraphParser().graphContraction(correspondentGraph);
			
			assertTrue(annotatedGraph.getEdges().size() == 5);
			assertTrue(annotatedGraph.getStates().values().size() == 6);
			
			InterfaceGenerate generator = new TestCaseGenerator();
			TestSuite generatedSuite = generator.generate(annotatedGraph);
			
			assertTrue(generatedSuite.size() == 2);
			
			TestSuiteXMLParser parser = new TestSuiteXMLParser();
			parser.write(generatedSuite, graphOneConditionBeginningOutputFilePath);
			
			TestSuite fromXMLTestSuite = new TestSuiteXMLParser().read(graphOneConditionBeginningOutputFilePath);
			
			assertTrue(fromXMLTestSuite.size() == 2);
			
			System.out.println();
			
			} catch (FileNotFoundException e) {
				System.out.println(e.getClass() + ": " + e.getLocalizedMessage());
			} catch (LTSBTException e) {
				System.out.println(e.getClass() + ": " + e.getLocalizedMessage());
			} catch (IOException e) {
				System.out.println(e.getClass() + ": " + e.getLocalizedMessage());
			} catch (Exception e) {
				System.out.println(e.getClass() + ": " + e.getLocalizedMessage());
			}
			
	}
	@Test
	public void mediumTestSuite(){
		
	}
	
	@Test
	public void testSuiteWithLoop(){
		
	}
}
